<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>19.原来数据也可以使用构造函数构建</title>
</head>

<body>
  <script>
    //JS 中大部分数据类型都是通过构造函数创建的。
    const num = new Number(99);
    console.log(num.valueOf());

    const string = new String("后盾人");
    console.log(string.valueOf());

    const boolean = new Boolean(true);
    console.log(boolean.valueOf());
    console.log(boolean.toString());

    const date = new Date();
    console.log(date.valueOf() * 1);

    const regexp = new RegExp("\\d+");
    console.log(regexp.test(99));

    /*let hd = new Object();
    hd.name = "后盾人";
    console.log(hd);*/
    //字面量创建的对象，内部也是调用了Object构造函数
    const obj = {
      name: "后盾人"
    };
    console.log(obj.constructor); //ƒ Object() { [native code] }

    //下面是使用构造函数创建对象
    const hdcms = new Object();
    hdcms.title = "开源内容管理系统";
    console.log(hdcms);
    //在JS中函数也是一个对象
    function hd (name) { }

    console.log(hd.toString());
    console.log(hd.length);
    //函数是由系统内置的 Function 构造函数创建的
    console.log(hd.constructor);

    // 下面是使用内置构造函数创建的函数
    const User = new Function(`name`, `
  this.name = name;
  this.show = function() {
    return this.name;
  };
`
    );

    const lisi = new User("李四");
    console.log(lisi.show()); //  李四
    // 使用构造函数也是可以的都是
    let User2 = new hd.constructor(`name`, `
  this.name = name;
  this.show = function() {
    return this.name;
  };
`
    );
    let xj = new User2('湘军');
    console.log(xj.show());

  </script>
</body>

</html>